<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			X-admin v1.0
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">
		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="js/rmodal.js"></script>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script src="./js/x-layui.js" charset="utf-8"></script>
		<script src="js/jquery.min.js"></script>
		
	</head>

	<body onload="findall()">
		<div class="x-nav">
			<span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>管理员列表</cite></a>
            </span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="x-body">
			<xblock><button class="layui-btn layui-btn-danger" onclick="batchdelete()">
            		批量删除</button>
				<button class="layui-btn" onclick="insertuser()">
            		<i class="layui-icon">&#xe608;</i>添加</button>
				<span class="x-right" style="line-height:40px">管理员账号请谨慎添加，分工不明会导致商品、订单等信息错乱</span>
			</xblock>
			<table class="layui-table">
				<thead>
					<tr>
						<th>
							<input type="checkbox" name="" value="">
						</th>
						<th>
							ID
						</th>
						<th>
							登录账号
						</th>
						<th>
							手机
						</th>
						<th>
							登录名称
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>
				<tbody id="userslist">

				</tbody>
			</table>
			<div id="page"></div>
		</div>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script src="./js/x-layui.js" charset="utf-8"></script>

		<script type="text/javascript">
			function findall() {
				var settings = {
					"url": "http://127.0.0.1:8080/user/findall",
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};
				$.ajax(settings).done(function(response) {
					var msg = "";
					var a = 1;
					for(var i = 0; i < response.length; i++) {
						msg += '<tr> <td>';
						msg += '<input type=\"checkbox\" value=\"' + response[i].userId + '\" id=\"commentId\" name=\"commentId\"></td> ';
						msg += '<td>' + a + '</td> ';
						msg += '<td>' + response[i].userEntername + '</td>';
						msg += '<td>' + response[i].userNumber + '</td>';
						msg += '<td>' + response[i].userName + '</td>';
						msg += '<td class=\"td-manage\"> ';
						msg += ' <a title=\"编辑\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateById(' + response[i].userId + ')\">';
						msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 25;\" height=\"25\"></i>';
						msg += '</a>&nbsp;&nbsp;';
						msg += ' <a title=\"删除\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"deleteById(' + response[i].userId + ')\">';
						msg += '<i class=\"layui-icon\"><img src=\"images/删除.png\" style="width: 25;\" height=\"25\"></i>';
						msg += '</a></td> </tr>';
					}
					$("#userslist").html(msg);
				});
			}
		</script>
		<script type="text/javascript">
			function deleteById(userId) {
				xtip.confirm('确认删除吗？', function() {
					var url = 'http://127.0.0.1:8080/user/delete?userId=' + userId;
					var settings = {
						"url": url,
						"method": "POST",
						"timeout": 0,
						"headers": {
							"Content-Type": "application/json"
						},
					};
					$.ajax(settings).done(function(response) {
						xtip.msg('删除成功',{times:1});
						location.href="./admin-list.html";
					});
				});
			}
		</script>
		<script>
			layui.use(['layer'], function(){
              layer = layui.layer;//弹出层
            });
			function updateById(userId){
				var url = 'http://127.0.0.1:8080/user/finduser?userId=' + userId;
					$.ajax({
						type: "post", //post方式传输，比get更加密安全
						url: url, //请求地址
						success: function(data) {
							sessionStorage.setItem("userId", JSON.stringify(data.userId));
							sessionStorage.setItem("userEntername", JSON.stringify(data.userEntername));
							sessionStorage.setItem("userNumber", JSON.stringify(data.userNumber));
							sessionStorage.setItem("userName", JSON.stringify(data.userName));
							sessionStorage.setItem("userPwd", JSON.stringify(data.userPwd));
							x_admin_show("用户编辑",'./admin-edit.html','600','500');
						},
						error: function() {
							alert("失败");
						}
					})
			}
		</script>
		<script>
			function insertuser(){
				location.href="./admin-add.html";
			}
		</script>
	</body>

</html>